namespace SimpleWebServices.Web.UI.Html.Elements
{
    using System.Xml.Serialization;
    using SimpleWebServices;
    using Xunit;

    public sealed class TableFacts
    {
        [Fact]
        public void typedef()
        {
            Assert.True(new ObjectExpectations<Table>()
                .DerivesFrom<InnerElements>()
                .IsConcreteClass()
                .IsUnsealed()
                .HasDefaultConstructor()
                .Implements<IXmlSerializable>()
                .XmlRoot("table")
                .Result);
        }

        [Fact]
        public void deserialize()
        {
            Table expected = new Table
            {
                Id = "id",
                Class = "class",
                Language = "fr",
                Title = "title",
                Elements =
                {
                    new TextString("Some text")
                }
            };

            string xml = "<table id='id' class='class' lang='fr' title='title'>Some text</table>";
            Table actual = xml.Deserialize<Table>();

            Assert.Equal<string>(expected.ToString(), actual.ToString());
        }

        [Fact]
        public void deserializeEmpty()
        {
            Assert.NotNull("<table />".Deserialize<Table>());
        }

        [Fact]
        public void serialize()
        {
            Table obj = new Table
            {
                Id = "id",
                Class = "class",
                Language = "fr",
                Title = "title",
                Elements =
                {
                    new TextString("Some text")
                }
            };

            string xpath = "1=count(/table[@id='id'][@class='class'][@lang='fr'][@title='title'][text()='Some text'])";

            Assert.True((bool)obj.Serialize().CreateNavigator().Evaluate(xpath));
        }

        [Fact]
        public void ctor()
        {
            Assert.NotNull(new Table());
        }

        [Fact]
        public void prop_Border()
        {
            Assert.True(new PropertyExpectations(typeof(Table).GetProperty("Border"))
                .IsAutoProperty<string>()
                .Result);
        }

        [Fact]
        public void prop_CellPadding()
        {
            Assert.True(new PropertyExpectations(typeof(Table).GetProperty("CellPadding"))
                .IsAutoProperty<string>()
                .Result);
        }

        [Fact]
        public void prop_CellSpacing()
        {
            Assert.True(new PropertyExpectations(typeof(Table).GetProperty("CellSpacing"))
                .IsAutoProperty<string>()
                .Result);
        }

        [Fact]
        public void prop_Frame()
        {
            Assert.True(new PropertyExpectations(typeof(Table).GetProperty("Frame"))
                .IsAutoProperty<string>()
                .Result);
        }

        [Fact]
        public void prop_Rules()
        {
            Assert.True(new PropertyExpectations(typeof(Table).GetProperty("Rules"))
                .IsAutoProperty<string>()
                .Result);
        }

        [Fact]
        public void prop_Summary()
        {
            Assert.True(new PropertyExpectations(typeof(Table).GetProperty("Summary"))
                .IsAutoProperty<string>()
                .Result);
        }

        [Fact]
        public void prop_Width()
        {
            Assert.True(new PropertyExpectations(typeof(Table).GetProperty("Width"))
                .IsAutoProperty<string>()
                .Result);
        }

        [Fact]
        public void op_Deserialize_string_string_string()
        {
            Table expected = new Table
            {
                Id = "id",
                Class = "class",
                Language = "fr",
                Title = "title",
                Border = "1",
                CellPadding = "10%",
                CellSpacing = "20",
                Frame = "box",
                Rules = "all",
                Summary = "Summary",
                Width = "90%"
            };

            string xml = "<table" +
                " id='id'" +
                " class='class'" +
                " lang='fr'" +
                " title='title'" +
                " border='1'" +
                " cellpadding='10%'" +
                " cellspacing='20'" +
                " frame='box'" +
                " rules='all'" +
                " summary='Summary'" +
                " width='90%'" +
                "/>";
            Table actual = new Table().Deserialize("table", null, xml) as Table;

            Assert.Equal<string>(expected.ToString(), actual.ToString());
        }
    }
}